package xyz.ddlnt.serviceusr.controller;

import jakarta.annotation.Resource;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import xyz.ddlnt.commonutil.result.Result;
import xyz.ddlnt.model.entity.ExamQuestion;
import xyz.ddlnt.model.vo.ExamQuestionIntroVO;
import xyz.ddlnt.serviceusr.service.ExamQuestionService;

import java.util.List;

/**
 * @author ZZULI_SE 210910
 * @data 2025/5/5 1:57
 */
@Slf4j
@RequestMapping("/exam_question")
@RestController
public class ExamQuestionController {
    @Resource
    private ExamQuestionService examQuestionService;

    /**
     * 根据技术科目Id查询试题简介
     * @param technologyId
     * @return
     */
    @GetMapping("/listExamQuesIntro")
    public Result<List<ExamQuestionIntroVO>> listExamQuestionIntro(@RequestParam Long technologyId) {
        List<ExamQuestionIntroVO> examQuestionIntroVOS = examQuestionService.listExamQuestionIntroVO(technologyId);
        return Result.success(examQuestionIntroVOS);
    }

    /**
     * 根据技术科目Id查询试题目录
     * @param technologyId
     * @return
     */
    @GetMapping("/listExamQuesIntroDir")
    public Result<List<ExamQuestionIntroVO>> listExamQuestionIntroDir(@RequestParam Long technologyId) {
        List<ExamQuestionIntroVO> examQuestionIntroVOS = examQuestionService.listExamQuestionIntroDir(technologyId);
        return Result.success(examQuestionIntroVOS);
    }

    /**
     * 获取试题的所有信息
     * @param questionId
     * @return
     */
    @Cacheable(value = "examQuestionInfo", key = "#questionId")
    @GetMapping("/examQuestionInfo")
    public Result<ExamQuestion> getExamQuestionInfo(@RequestParam Long questionId) {
        ExamQuestion examQuestion = examQuestionService.getById(questionId);
        return Result.success(examQuestion);
    }
}
